Forage_plot_spring
lm_FecundityYear <- lm(Fecundity_year ~Elevation+Species+Loc_type, data = res_ecto_stats_spring)
lm_FecundityYear_int <- lm(Fecundity_year ~ Elevation*Species+Loc_type, data = res_ecto_stats_spring)
lm_FecundityYear_int2<- lm(Fecundity_year ~Elevation*Loc_type+Species, data = res_ecto_stats_spring)
lm_FecundityYear_int3<- lm(Fecundity_year ~Elevation+Loc_type*Species, data = res_ecto_stats_spring)
lm_FecundityYear_int4<- lm(Fecundity_year ~Elevation*Loc_type*Species, data = res_ecto_stats_spring)
Fecundity_plot_spring <-  visualize(lm_FecundityYear_int, Fecundity_year~Elevation + Loc_type|Species, method="lm", plot="model")+
scale_color_manual(values = c("firebrick", "gold", "navyblue"))+
scale_shape_manual(values =c(19, 19, 19))+
scale_linetype_manual(values =c(1, 1, 1))+
theme_classic()+
labs_pubr()+
labs(title = NULL, y=expression(paste("Mean yearly fecundity \n      (n. offspring)")), x="Elevation (m)")+
theme(strip.background = element_blank(),
strip.text.x = element_blank(),
axis.text=element_text(size=11),
axis.title=element_text(size=12,face="bold"))+
facet_wrap(~Species)
Fecundity_plot_spring
## alt plot
plot_ecto_spring_vert <- ggarrange(EggDev_plot_spring, Lifespan_plot_spring, YearsRepro_plot_spring, Basking_plot_spring, Forage_plot_spring, Fecundity_plot_spring, nrow = 6, ncol = 1, labels = NULL, common.legend = FALSE, legend = "none", font.label = list(size = 13, color = "black", face = "bold"))
plot_ecto_spring_vert
ggsave("plot_ecto_spring_vert.pdf", plot=plot_ecto_spring_vert, path = "../../Figures/Ectotherm_plots/", units="cm", width=20, height=40, dpi=300)
ggsave("plot_ecto_spring_vert.pdf", plot=plot_ecto_spring_vert, path = "../../Figures/Ectotherm_plots/", units="cm", width=20, height=40, dpi=300)
ggsave("plot_ecto_spring_vert.svg", plot=plot_ecto_spring_vert, path = "../../Figures/Ectotherm_plots/", units="cm", width=20, height=40, dpi=300)
ggsave("plot_ecto_spring_vert.pdf", plot=plot_ecto_spring_vert, path = "../../Figures/Ectotherm_plots/", units="cm", width=20, height=40, dpi=300)
ggsave("plot_ecto_spring_vert.svg", plot=plot_ecto_spring_vert, path = "../../Figures/Ectotherm_plots/", units="cm", width=20, height=40, dpi=300)
ggsave("plot_ecto_spring_vert.png", plot=plot_ecto_spring_vert, path = "../../Figures/Ectotherm_plots/", units="cm", width=20, height=40, dpi=300, bg="white")
ggsave("plot_ecto_spring_vert.pdf", plot=plot_ecto_spring_vert, path = "../../Figures/Ectotherm_plots/", units="cm", width=30, height=40, dpi=300)
ggsave("plot_ecto_spring_vert.png", plot=plot_ecto_spring_vert, path = "../../Figures/Ectotherm_plots/", units="cm", width=30, height=40, dpi=300, bg="white")
ggsave("plot_ecto_spring_vert.pdf", plot=plot_ecto_spring_vert, path = "../../Figures/Ectotherm_plots/", units="cm", width=40, height=40, dpi=300)
ggsave("plot_ecto_spring_vert.png", plot=plot_ecto_spring_vert, path = "../../Figures/Ectotherm_plots/", units="cm", width=20, height=40, dpi=300, bg="white")
Fecundity_plot_spring <-  visualize(lm_FecundityYear_int, Fecundity_year~Elevation + Loc_type|Species, method="lm", plot="model")+
scale_color_manual(values = c("firebrick", "gold", "navyblue"))+
scale_shape_manual(values =c(19, 19, 19))+
scale_linetype_manual(values =c(1, 1, 1))+
theme_classic()+
labs_pubr()+
labs(title = NULL, y=expression(paste("Mean yearly fecundity \n      (n. offspring)")), x="Elevation (m)")+
theme(strip.background = element_blank(),
strip.text.x = element_blank(),
axis.text=element_text(size=11),
axis.title=element_text(size=12,face="bold"))+
scale_x_continuous(expand = expansion(mult = c(0, 0.15)))+
facet_wrap(~Species)
Fecundity_plot_spring
Fecundity_plot_spring <-  visualize(lm_FecundityYear_int, Fecundity_year~Elevation + Loc_type|Species, method="lm", plot="model")+
scale_color_manual(values = c("firebrick", "gold", "navyblue"))+
scale_shape_manual(values =c(19, 19, 19))+
scale_linetype_manual(values =c(1, 1, 1))+
theme_classic()+
labs_pubr()+
labs(title = NULL, y=expression(paste("Mean yearly fecundity \n      (n. offspring)")), x="Elevation (m)")+
theme(strip.background = element_blank(),
strip.text.x = element_blank(),
axis.text=element_text(size=11),
axis.title=element_text(size=12,face="bold"))+
scale_x_continuous(expand = expansion(mult = c(0, 0.50)))+
facet_wrap(~Species)
Fecundity_plot_spring
Fecundity_plot_spring <-  visualize(lm_FecundityYear_int, Fecundity_year~Elevation + Loc_type|Species, method="lm", plot="model")+
scale_color_manual(values = c("firebrick", "gold", "navyblue"))+
scale_shape_manual(values =c(19, 19, 19))+
scale_linetype_manual(values =c(1, 1, 1))+
theme_classic()+
labs_pubr()+
labs(title = NULL, y=expression(paste("Mean yearly fecundity \n      (n. offspring)")), x="Elevation (m)")+
theme(strip.background = element_blank(),
strip.text.x = element_blank(),
axis.text=element_text(size=11),
axis.title=element_text(size=12,face="bold"))+
scale_x_continuous(expand = expansion(mult = c(0, 0.05)))+
facet_wrap(~Species)
Fecundity_plot_spring
Fecundity_plot_spring <-  visualize(lm_FecundityYear_int, Fecundity_year~Elevation + Loc_type|Species, method="lm", plot="model")+
scale_color_manual(values = c("firebrick", "gold", "navyblue"))+
scale_shape_manual(values =c(19, 19, 19))+
scale_linetype_manual(values =c(1, 1, 1))+
theme_classic()+
labs_pubr()+
labs(title = NULL, y=expression(paste("Mean yearly fecundity \n      (n. offspring)")), x="Elevation (m)")+
theme(strip.background = element_blank(),
strip.text.x = element_blank(),
axis.text=element_text(size=11),
axis.title=element_text(size=12,face="bold"))+
facet_wrap(~Species)
Fecundity_plot_spring
## alt plot
plot_ecto_spring_vert <- ggarrange(EggDev_plot_spring, Lifespan_plot_spring, YearsRepro_plot_spring, Basking_plot_spring, Forage_plot_spring, Fecundity_plot_spring, nrow = 6, ncol = 1, labels = NULL, common.legend = FALSE, legend = "none", font.label = list(size = 13, color = "black", face = "bold"))
plot_ecto_spring_vert
ggsave("plot_ecto_spring_vert.pdf", plot=plot_ecto_spring_vert, path = "../../Figures/Ectotherm_plots/", units="cm", width=20, height=40, dpi=300)
ggsave("plot_ecto_spring_vert.pdf", plot=plot_ecto_spring_vert, path = "../../Figures/Ectotherm_plots/", units="cm", width=10, height=20, dpi=300)
ggsave("plot_ecto_spring_vert.pdf", plot=plot_ecto_spring_vert, path = "../../Figures/Ectotherm_plots/", units="cm", width=50, height=30, dpi=300)
ggsave("plot_ecto_spring_vert.pdf", plot=plot_ecto_spring_vert, path = "../../Figures/Ectotherm_plots/", units="cm", width=15, height=30, dpi=300)
ggsave("plot_ecto_spring_vert.pdf", plot=plot_ecto_spring_vert, path = "../../Figures/Ectotherm_plots/", units="cm", width=20, height=30, dpi=300)
ggsave("plot_ecto_spring_vert.svg", plot=plot_ecto_spring_vert, path = "../../Figures/Ectotherm_plots/", units="cm", width=20, height=40, dpi=300)
ggsave("plot_ecto_spring_vert.png", plot=plot_ecto_spring_vert, path = "../../Figures/Ectotherm_plots/", units="cm", width=20, height=40, dpi=300, bg="white")
Lifespan_plot_spring <-   visulize(lm_Lifespan, LifeSpan~Elevation + Loc_type|Species, method="lm", plot="model")+
scale_color_manual(values = c("firebrick", "gold", "navyblue"))+
scale_shape_manual(values =c(19, 19, 19))+
scale_linetype_manual(values =c(1, 1, 1))+
theme_classic()+
labs_pubr()+
labs(title = NULL, y=expression(paste("Lifespan (years)")), x=NULL)+
theme(
#strip.text = element_text(face = "italic"),
#axis.text=element_text(size=11),
#axis.title=element_text(size=12,face="bold")
strip.background = element_blank(),
strip.text.x = element_blank())+
facet_wrap(~Species)
Lifespan_plot_spring <-   visualize(lm_Lifespan, LifeSpan~Elevation + Loc_type|Species, method="lm", plot="model")+
scale_color_manual(values = c("firebrick", "gold", "navyblue"))+
scale_shape_manual(values =c(19, 19, 19))+
scale_linetype_manual(values =c(1, 1, 1))+
theme_classic()+
labs_pubr()+
labs(title = NULL, y=expression(paste("Lifespan (years)")), x=NULL)+
theme(
#strip.text = element_text(face = "italic"),
#axis.text=element_text(size=11),
#axis.title=element_text(size=12,face="bold")
strip.background = element_blank(),
strip.text.x = element_blank())+
facet_wrap(~Species)
Lifespan_plot_spring
## alt plot
plot_ecto_spring_vert <- ggarrange(EggDev_plot_spring, Lifespan_plot_spring, YearsRepro_plot_spring, Basking_plot_spring, Forage_plot_spring, Fecundity_plot_spring, nrow = 6, ncol = 1, labels = NULL, common.legend = FALSE, legend = "none", font.label = list(size = 13, color = "black", face = "bold"))
plot_ecto_spring_vert
ggsave("plot_ecto_spring_vert.pdf", plot=plot_ecto_spring_vert, path = "../../Figures/Ectotherm_plots/", units="cm", width=20, height=30, dpi=300)
ggsave("plot_ecto_spring_vert.svg", plot=plot_ecto_spring_vert, path = "../../Figures/Ectotherm_plots/", units="cm", width=20, height=40, dpi=300)
ggsave("plot_ecto_spring_vert.png", plot=plot_ecto_spring_vert, path = "../../Figures/Ectotherm_plots/", units="cm", width=20, height=40, dpi=300, bg="white")
## alt plot
plot_ecto_spring_vert <- ggarrange(EggDev_plot_spring, Lifespan_plot_spring, YearsRepro_plot_spring, Basking_plot_spring, Forage_plot_spring, Fecundity_plot_spring, nrow = 6, ncol = 1, labels = NULL, common.legend = FALSE, legend = "none", font.label = list(size = 10, color = "black", face = "bold"))
plot_ecto_spring_vert
ggsave("plot_ecto_spring_vert.pdf", plot=plot_ecto_spring_vert, path = "../../Figures/Ectotherm_plots/", units="cm", width=20, height=30, dpi=300)
ggsave("plot_ecto_spring_vert.svg", plot=plot_ecto_spring_vert, path = "../../Figures/Ectotherm_plots/", units="cm", width=20, height=40, dpi=300)
ggsave("plot_ecto_spring_vert.pdf", plot=plot_ecto_spring_vert, path = "../../Figures/Ectotherm_plots/", units="cm", width=25, height=35, dpi=300)
ggsave("plot_ecto_spring_vert.svg", plot=plot_ecto_spring_vert, path = "../../Figures/Ectotherm_plots/", units="cm", width=20, height=40, dpi=300)
ggsave("plot_ecto_spring_vert.png", plot=plot_ecto_spring_vert, path = "../../Figures/Ectotherm_plots/", units="cm", width=20, height=40, dpi=300, bg="white")
ggsave("plot_ecto_spring_vert.pdf", plot=plot_ecto_spring_vert, path = "../../Figures/Ectotherm_plots/", units="cm", width=20, height=35, dpi=300)
ggsave("plot_ecto_spring_vert.svg", plot=plot_ecto_spring_vert, path = "../../Figures/Ectotherm_plots/", units="cm", width=20, height=40, dpi=300)
ggsave("plot_ecto_spring_vert.png", plot=plot_ecto_spring_vert, path = "../../Figures/Ectotherm_plots/", units="cm", width=20, height=40, dpi=300, bg="white")
ggsave("plot_ecto_spring_vert.pdf", plot=plot_ecto_spring_vert, path = "../../Figures/Ectotherm_plots/", units="cm", width=20, height=35, dpi=300)
ggsave("plot_ecto_spring_vert.svg", plot=plot_ecto_spring_vert, path = "../../Figures/Ectotherm_plots/", units="cm", width=20, height=35, dpi=300)
ggsave("plot_ecto_spring_vert.png", plot=plot_ecto_spring_vert, path = "../../Figures/Ectotherm_plots/", units="cm", width=20, height=35, dpi=300, bg="white")
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_chunk$set(message=FALSE)
knitr::opts_chunk$set(warning=FALSE)
knitr::opts_chunk$set(tidy=TRUE)
rm(list = ls())
getwd()
load("../../Results/ECTOTHERM_results/results_all_ecto_summerTP.Rda")
res_ecto_stats <- results_all
#Get yearly values
res_ecto_stats$Forage_year <- res_ecto_stats$Forage/res_ecto_stats$Year
res_ecto_stats$Bask_year <- res_ecto_stats$Bask/res_ecto_stats$Year
res_ecto_stats$Fecundity_year <- res_ecto_stats$Fecundity/res_ecto_stats$Year
res_ecto_stats$Clutches_year <- res_ecto_stats$Clutches/res_ecto_stats$Year
#Rename values
res_ecto_stats$Species[res_ecto_stats$Species == "Ihor"] <- "I. horvathi"
res_ecto_stats$Species[res_ecto_stats$Species == "Pmur"] <- "P. muralis"
res_ecto_stats$Sintopy[res_ecto_stats$Sintopy == "sint"] <- "Sintopy"
res_ecto_stats$Sintopy[res_ecto_stats$Sintopy == "aloPmur"] <- "Muralis allotopy"
res_ecto_stats$Sintopy[res_ecto_stats$Sintopy == "aloIhor"] <- "Horvathi allotopy"
#Turn to factor
res_ecto_stats$Locality <- as.factor(res_ecto_stats$Locality)
res_ecto_stats$Sintopy <- as.factor(res_ecto_stats$Sintopy)
res_ecto_stats$Species <- as.factor(res_ecto_stats$Species)
str(res_ecto_stats)
res_ecto_stats <- res_ecto_stats %>%
rename(Loc_type = Sintopy)
res_ecto_stats <- res_ecto_stats[, c("Locality", "Elevation", "Loc_type", "Species", "MeanTALOC", "MeanRHLOC", "Solar", "NO_Snow", "egg_dev", "LifeSpan", "Years_repro", "Bask_year", "Forage_year", "Fecundity_year")]
head(res_ecto_stats)
str(res_ecto_stats)
## Microclimate analysis table
loc_stats <- res_ecto_stats %>% distinct(MeanTALOC, .keep_all = TRUE)
#Check lm model first
lm_eggDev <- lm(egg_dev ~ Elevation+Species+Loc_type, data = res_ecto_stats)
lm_eggDev_int <- lm(egg_dev ~ Elevation*Species+Loc_type, data = res_ecto_stats)
lm_eggDev_int2<- lm(egg_dev ~ Elevation*Loc_type+Species, data = res_ecto_stats)
lm_eggDev_int3<- lm(egg_dev ~ Elevation+Loc_type*Species, data = res_ecto_stats)
lm_eggDev_int4<- lm(egg_dev ~ Elevation*Loc_type*Species, data = res_ecto_stats)
EggDev_plot <- visualize(lm_eggDev, egg_dev~Elevation+Loc_type |Species, method="lm", plot="model")+
scale_color_manual(values = c("firebrick", "gold", "navyblue"))+
scale_shape_manual(values =c(19, 19, 19))+
scale_linetype_manual(values =c(1, 1, 1))+
theme_classic()+
labs_pubr()+
labs(title = NULL, y=expression(paste("Egg development time (days)")), x=NULL)+
theme(
strip.text = element_text(face = "italic"),
axis.text=element_text(size=11),
axis.title=element_text(size=12,face="bold"))+
facet_wrap(~Species)
EggDev_plot
lm_Lifespan <- lm(LifeSpan ~ Elevation + Species+ Loc_type, data = res_ecto_stats)
lm_Lifespan_int <- lm(LifeSpan ~ Elevation*Species+Loc_type, data = res_ecto_stats)
lm_Lifespan_int2<- lm(LifeSpan ~ Elevation*Loc_type+Species, data = res_ecto_stats)
lm_Lifespan_int3<- lm(LifeSpan ~ Elevation+Loc_type*Species, data = res_ecto_stats)
lm_Lifespan_int4<- lm(LifeSpan ~ Elevation*Loc_type*Species, data = res_ecto_stats)
Lifespan_plot <-   visualize(lm_Lifespan, LifeSpan~Elevation + Loc_type|Species, method="lm", plot="model")+
scale_color_manual(values = c("firebrick", "gold", "navyblue"))+
scale_shape_manual(values =c(19, 19, 19))+
scale_linetype_manual(values =c(1, 1, 1))+
theme_classic()+
labs_pubr()+
labs(title = NULL, y=expression(paste("Lifespan (years)")), x=NULL)+
theme(
strip.text = element_text(face = "italic"),
axis.text=element_text(size=11),
axis.title=element_text(size=12,face="bold"))+
facet_wrap(~Species)
Lifespan_plot
Lifespan_plot <-   visualize(lm_Lifespan, LifeSpan~Elevation + Loc_type|Species, method="lm", plot="model")+
scale_color_manual(values = c("firebrick", "gold", "navyblue"))+
scale_shape_manual(values =c(19, 19, 19))+
scale_linetype_manual(values =c(1, 1, 1))+
theme_classic()+
labs_pubr()+
labs(title = NULL, y=expression(paste("Lifespan (years)")), x=NULL)+
theme(
#strip.text = element_text(face = "italic"),
#axis.text=element_text(size=11),
#axis.title=element_text(size=12,face="bold")
strip.background = element_blank(),
strip.text.x = element_blank())+
facet_wrap(~Species)
Lifespan_plot
#Check lm model first
lm_YearsRepro_noLoc <- lm(Years_repro ~ Elevation + Species, data = res_ecto_stats)
lm_YearsRepro <- lm(Years_repro ~ Elevation + Species + Loc_type, data = res_ecto_stats)
lm_YearsRepro_int <- lm(Years_repro ~ Elevation*Species+Loc_type, data = res_ecto_stats)
lm_YearsRepro_int2<- lm(Years_repro ~ Elevation*Loc_type+Species, data = res_ecto_stats)
lm_YearsRepro_int3<- lm(Years_repro ~ Elevation+Loc_type*Species, data = res_ecto_stats)
lm_YearsRepro_int4<- lm(Years_repro ~ Elevation*Loc_type*Species, data = res_ecto_stats)
YearsRepro_plot <-  visualize(lm_YearsRepro_noLoc, Years_repro~Elevation | Species, method="lm", plot="model")+
scale_color_manual(values = c("black"))+
theme_classic()+
labs_pubr()+
labs(title = NULL, y=expression(paste("Years reproducing (years)")), x=NULL)+
theme(strip.background = element_blank(),
strip.text.x = element_blank(),
axis.text=element_text(size=11),
axis.title=element_text(size=12,face="bold"))+
facet_wrap(~Species)
YearsRepro_plot
#Check lm model first
lm_BaskYear <- lm(Bask_year ~ Elevation + Species + Loc_type, data = res_ecto_stats)
lm_BaskYear_int <- lm(Bask_year ~ Elevation*Species+Loc_type, data = res_ecto_stats)
lm_BaskYear_int2<- lm(Bask_year ~ Elevation*Loc_type+Species, data = res_ecto_stats)
lm_BaskYear_int3<- lm(Bask_year ~ Elevation+Loc_type*Species, data = res_ecto_stats)
lm_BaskYear_int4<- lm(Bask_year ~ Elevation*Loc_type*Species, data = res_ecto_stats)
Basking_plot <- visualize(lm_BaskYear, Bask_year~Elevation + Loc_type|Species, method="lm", plot="model")+
scale_color_manual(values = c("firebrick", "gold", "navyblue"))+
scale_shape_manual(values =c(19, 19, 19))+
scale_linetype_manual(values =c(1, 1, 1))+
theme_classic()+
labs_pubr()+
labs(title = NULL, y=expression(paste("Mean yearly basking time (hours)")), x=NULL)+
theme(strip.background = element_blank(),
strip.text.x = element_blank(),
axis.text=element_text(size=11),
axis.title=element_text(size=12,face="bold"))+
facet_wrap(~Species)
Basking_plot
lm_ForageYear <- lm(Forage_year ~ Elevation + Species + Loc_type, data = res_ecto_stats)
lm_ForageYear_int <- lm(Forage_year ~ Elevation*Species+Loc_type, data = res_ecto_stats)
lm_ForageYear_int2<- lm(Forage_year ~ Elevation*Loc_type+Species, data = res_ecto_stats)
lm_ForageYear_int3<- lm(Forage_year ~ Elevation+Loc_type*Species, data = res_ecto_stats)
lm_ForageYear_int4<- lm(Forage_year ~ Elevation*Loc_type*Species, data = res_ecto_stats)
Forage_plot <-  visualize(lm_ForageYear, Forage_year~Elevation + Loc_type|Species,method="lm", plot="model")+
scale_color_manual(values = c("firebrick", "gold", "navyblue"))+
scale_shape_manual(values =c(19, 19, 19))+
scale_linetype_manual(values =c(1, 1, 1))+
theme_classic()+
labs_pubr()+
labs(title = NULL, y=expression(paste("Mean yearly foraging time (hours)")), x="Elevation (m)")+
theme(strip.background = element_blank(),
strip.text.x = element_blank(),
axis.text=element_text(size=11),
axis.title=element_text(size=12,face="bold"))+
facet_wrap(~Species)
Forage_plot
lm_FecundityYear <- lm(Fecundity_year ~Elevation+Species+Loc_type, data = res_ecto_stats)
lm_FecundityYear_int <- lm(Fecundity_year ~ Elevation*Species+Loc_type, data = res_ecto_stats)
lm_FecundityYear_int2<- lm(Fecundity_year ~Elevation*Loc_type+Species, data = res_ecto_stats)
lm_FecundityYear_int3<- lm(Fecundity_year ~Elevation+Loc_type*Species, data = res_ecto_stats)
lm_FecundityYear_int4<- lm(Fecundity_year ~Elevation*Loc_type*Species, data = res_ecto_stats)
Fecundity_plot <-  visualize(lm_FecundityYear_int, Fecundity_year~Elevation + Loc_type|Species, method="lm", plot="model")+
scale_color_manual(values = c("firebrick", "gold", "navyblue"))+
scale_shape_manual(values =c(19, 19, 19))+
scale_linetype_manual(values =c(1, 1, 1))+
theme_classic()+
labs_pubr()+
labs(title = NULL, y=expression(paste("Mean yearly fecundity \n      (n. offspring)")), x="Elevation (m)")+
theme(strip.background = element_blank(),
strip.text.x = element_blank(),
axis.text=element_text(size=11),
axis.title=element_text(size=12,face="bold"))+
facet_wrap(~Species)
Fecundity_plot
plot_ecto_vert <- ggarrange(EggDev_plot, Lifespan_plot, YearsRepro_plot, Basking_plot, Forage_plot, Fecundity_plot, nrow = 6, ncol = 1, labels = NULL, common.legend = FALSE, legend = "none", font.label = list(size = 13, color = "black", face = "bold"))
plot_ecto_vert
ggsave("plot_ecto_vert.pdf", plot=plot_ecto_vert, path = "../../Figures/Ectotherm_plots/", units="cm", width=20, height=35, dpi=300)
ggsave("plot_ecto_vert.svg", plot=plot_ecto_vert, path = "../../Figures/Ectotherm_plots/", units="cm", width=20, height=35, dpi=300)
ggsave("plot_ecto_vert.png", plot=plot_ecto_vert, path = "../../Figures/Ectotherm_plots/", units="cm", width=20, height=35, dpi=300, bg="white")
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_chunk$set(message=FALSE)
knitr::opts_chunk$set(warning=FALSE)
knitr::opts_chunk$set(tidy=TRUE)
rm(list = ls())
using<-function(...) {
libs<-unlist(list(...))
req<-unlist(lapply(libs,require,character.only=TRUE))
need<-libs[req==FALSE]
if(length(need)>0){
install.packages(need)
lapply(need,require,character.only=TRUE)
}
}
using("dplyr", "ggplot2", "ggpubr", "rstatix", "NCmisc", "car", "lme4", "DHARMa", "emmeans", "performance", "sjPlot", "rphylopic", "jpeg", "flexplot", "report", "broom", "ggfortify", "MASS", "jtools", "svglite",  "multcomp", "vegan", "showtext", "formatR", "AICcmodavg")
using("dplyr", "ggplot2", "ggpubr", "rstatix", "NCmisc", "car", "lme4", "DHARMa", "emmeans", "performance", "sjPlot", "rphylopic", "jpeg", "flexplot", "report", "broom", "ggfortify", "MASS", "jtools", "svglite",  "multcomp", "vegan", "showtext", "formatR", "AICcmodavg")
citation("AICcmodavg")
R.version
RStudio.Version()
citation("ggplot2")
citation("flexplot")
citation("ggarrange")
citation("ggpubr")
getwd()
load("../../Results/ECTOTHERM_results/results_all_ecto_summerTP.Rda")
res_ecto_stats <- results_all
#Get yearly values
res_ecto_stats$Forage_year <- res_ecto_stats$Forage/res_ecto_stats$Year
res_ecto_stats$Bask_year <- res_ecto_stats$Bask/res_ecto_stats$Year
res_ecto_stats$Fecundity_year <- res_ecto_stats$Fecundity/res_ecto_stats$Year
res_ecto_stats$Clutches_year <- res_ecto_stats$Clutches/res_ecto_stats$Year
#Rename values
res_ecto_stats$Species[res_ecto_stats$Species == "Ihor"] <- "I. horvathi"
res_ecto_stats$Species[res_ecto_stats$Species == "Pmur"] <- "P. muralis"
res_ecto_stats$Sintopy[res_ecto_stats$Sintopy == "sint"] <- "Sintopy"
res_ecto_stats$Sintopy[res_ecto_stats$Sintopy == "aloPmur"] <- "Muralis allotopy"
res_ecto_stats$Sintopy[res_ecto_stats$Sintopy == "aloIhor"] <- "Horvathi allotopy"
#Turn to factor
res_ecto_stats$Locality <- as.factor(res_ecto_stats$Locality)
res_ecto_stats$Sintopy <- as.factor(res_ecto_stats$Sintopy)
res_ecto_stats$Species <- as.factor(res_ecto_stats$Species)
str(res_ecto_stats)
res_ecto_stats <- res_ecto_stats %>%
rename(Loc_type = Sintopy)
res_ecto_stats <- res_ecto_stats[, c("Locality", "Elevation", "Loc_type", "Species", "MeanTALOC", "MeanRHLOC", "Solar", "NO_Snow", "egg_dev", "LifeSpan", "Years_repro", "Bask_year", "Forage_year", "Fecundity_year")]
head(res_ecto_stats)
str(res_ecto_stats)
## Microclimate analysis table
loc_stats <- res_ecto_stats %>% distinct(MeanTALOC, .keep_all = TRUE)
library(lmerTest)
library(MuMIn)
res_ecto_stats
#Check lm model first
lm_eggDev <- lm(egg_dev ~ Elevation+Species+Loc_type, data = res_ecto_stats)
lm_eggDev_int <- lm(egg_dev ~ Elevation*Species+Loc_type, data = res_ecto_stats)
lm_eggDev_int2<- lm(egg_dev ~ Elevation*Loc_type+Species, data = res_ecto_stats)
lm_eggDev_int3<- lm(egg_dev ~ Elevation+Loc_type*Species, data = res_ecto_stats)
lm_eggDev_int4<- lm(egg_dev ~ Elevation*Loc_type*Species, data = res_ecto_stats)
autoplot(lm_eggDev)+
theme_classic()
citation("NicheMapR")
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_chunk$set(message=FALSE)
knitr::opts_chunk$set(warning=FALSE)
knitr::opts_chunk$set(tidy=TRUE)
rm(list = ls())
using<-function(...) {
libs<-unlist(list(...))
req<-unlist(lapply(libs,require,character.only=TRUE))
need<-libs[req==FALSE]
if(length(need)>0){
install.packages(need)
lapply(need,require,character.only=TRUE)
}
}
using("dplyr", "ggplot2", "ggpubr", "rstatix", "NCmisc", "car", "lme4", "DHARMa", "emmeans", "performance", "sjPlot", "rphylopic", "jpeg", "flexplot", "report", "broom", "ggfortify", "MASS", "jtools", "svglite",  "multcomp", "vegan", "showtext", "formatR", "AICcmodavg")
getwd()
load("../../Results/ECTOTHERM_results/results_all_ecto_summerTP.Rda")
res_ecto_stats <- results_all
#Get yearly values
res_ecto_stats$Forage_year <- res_ecto_stats$Forage/res_ecto_stats$Year
res_ecto_stats$Bask_year <- res_ecto_stats$Bask/res_ecto_stats$Year
res_ecto_stats$Fecundity_year <- res_ecto_stats$Fecundity/res_ecto_stats$Year
res_ecto_stats$Clutches_year <- res_ecto_stats$Clutches/res_ecto_stats$Year
#Rename values
res_ecto_stats$Species[res_ecto_stats$Species == "Ihor"] <- "I. horvathi"
res_ecto_stats$Species[res_ecto_stats$Species == "Pmur"] <- "P. muralis"
res_ecto_stats$Sintopy[res_ecto_stats$Sintopy == "sint"] <- "Sintopy"
res_ecto_stats$Sintopy[res_ecto_stats$Sintopy == "aloPmur"] <- "Muralis allotopy"
res_ecto_stats$Sintopy[res_ecto_stats$Sintopy == "aloIhor"] <- "Horvathi allotopy"
#Turn to factor
res_ecto_stats$Locality <- as.factor(res_ecto_stats$Locality)
res_ecto_stats$Sintopy <- as.factor(res_ecto_stats$Sintopy)
res_ecto_stats$Species <- as.factor(res_ecto_stats$Species)
str(res_ecto_stats)
res_ecto_stats <- res_ecto_stats %>%
rename(Loc_type = Sintopy)
res_ecto_stats <- res_ecto_stats[, c("Locality", "Elevation", "Loc_type", "Species", "MeanTALOC", "MeanRHLOC", "Solar", "NO_Snow", "egg_dev", "LifeSpan", "Years_repro", "Bask_year", "Forage_year", "Fecundity_year")]
head(res_ecto_stats)
str(res_ecto_stats)
## Microclimate analysis table
loc_stats <- res_ecto_stats %>% distinct(MeanTALOC, .keep_all = TRUE)
#check data distribution
gghistogram(loc_stats$MeanTALOC, bins = 15)
ggboxplot(loc_stats$MeanTALOC)
#Check lm model
lm_MeanTALOC <- lm(MeanTALOC ~Elevation+Loc_type, data = loc_stats)
# Get summary and p values
summary(lm_MeanTALOC)
# Plot
lm_Plot_eTemp <- lm(MeanTALOC ~Elevation, data = loc_stats)
MeanTemp_plot <- visualize(lm_Plot_eTemp,  MeanTALOC ~Elevation, plot="model")+
scale_color_manual(values = c("black"))+
theme_classic()+
labs_pubr()+
labs(title = NULL, y=expression(paste("Mean temperature (°C)")), x=NULL)+
theme(legend.position="null")
MeanTemp_plot
#Check model fit, residuals etc.
autoplot(lm_MeanTALOC)+
theme_classic()
shapiro.test(residuals(lm_MeanTALOC))
#check data distribution
gghistogram(loc_stats$MeanRHLOC, bins = 15)
ggboxplot(loc_stats$MeanRHLOC)
#Check lm model first
lm_MeanRHLOC <- lm(MeanRHLOC ~Elevation+Loc_type, data = loc_stats)
# Get summary and p values
summary(lm_MeanRHLOC)
# Plot
lm_plot_eHum <- lm(MeanRHLOC ~Elevation, data = loc_stats)
Mean_humid <- visualize(lm_plot_eHum, MeanRHLOC ~ Elevation, plot="model")+
scale_color_manual(values = c("black"))+
theme_classic()+
labs_pubr()+
labs(title = NULL, y=expression(paste("Mean relative humidity (%)")), x=NULL)+
theme(legend.position="null")
Mean_humid
#Check model fit, residuals etc.
autoplot(lm_MeanRHLOC)+
theme_classic()
shapiro.test(residuals(lm_MeanRHLOC))
#check data distribution
gghistogram(loc_stats$Solar, bins = 5)
ggboxplot(loc_stats$Solar)
#Check lm model first
lm_Solar <- lm(Solar ~Elevation+Loc_type, data = loc_stats)
# Get summary and p values
summary(lm_Solar) #AIC delta <4, include interaction
# Plot
lm_solar_plot <- lm(Solar ~Elevation, data = loc_stats)
Mean_solar <- visualize(lm_solar_plot,  Solar ~ Elevation, plot="model")+
scale_color_manual(values = c("black"))+
theme_classic()+
#labs(title = NULL, y="Mean solar radiation (W/m2)", x=NULL)+
labs(title = NULL, y=expression(paste('Mean solar radiation' ~ " " ~ (W/m^{2}))), x=NULL)+
labs_pubr()+
theme(legend.position="null")
Mean_solar
#Check model fit, residuals etc.
autoplot(lm_Solar)+
theme_classic()
shapiro.test(residuals(lm_Solar))
#Check comparisons
summary(glht(lm_Solar, linfct = mcp(Loc_type = 'Tukey')))
#check data distribution
gghistogram(loc_stats$NO_Snow, bins = 50)
ggboxplot(loc_stats$NO_Snow)
#Check lm model first
lm_NO_Snow <- lm(NO_Snow ~ Elevation+Loc_type, data = loc_stats)
# Get summary and p values
summary(lm_NO_Snow)
# Plot
lm_plot_eSnow <- lm(NO_Snow ~ Elevation, data = loc_stats)
SnowDays_plot<- visualize(lm_plot_eSnow, NO_Snow ~ Elevation, plot="model")+
scale_color_manual(values = c("black"))+
theme_classic()+
labs_pubr()+
labs(title = NULL, y=expression(paste("Days without snow (n. days)")), x=NULL)+
theme(legend.position="null")
SnowDays_plot
#Check model fit, residuals etc.
autoplot(lm_NO_Snow)+
theme_classic()
shapiro.test(residuals(lm_NO_Snow))
plot_micro <- ggarrange(MeanTemp_plot, SnowDays_plot, Mean_solar, Mean_humid, nrow = 2, ncol = 2, labels = NULL,
common.legend = TRUE, legend = "none", font.label = list(size=13))
plot_micro
#ggsave("plot_micro_final_udpated.pdf", plot=plot_micro, path = "../../Figures/Ectotherm_plots/", units="cm", width=20, height=20, dpi=300)
#ggsave("plot_microfinal_updated.svg", plot=plot_micro, path = "../../Figures/Ectotherm_plots/", units="cm", width=20, height=20, dpi=300)
#ggsave("plot_micro_final_updated.png", plot=plot_micro, path = "../../Figures/Ectotherm_plots/", units="cm", width=20, height=20, dpi=300, bg="white")
# Get summary and p values
summary(lm_MeanTALOC)
# Get summary and p values
summary(lm_MeanRHLOC)
# Get summary and p values
summary(lm_Solar) #AIC delta <4, include interaction
lm_Lifespan <- lm(LifeSpan ~ Elevation + Species+ Loc_type, data = res_ecto_stats)
lm_Lifespan_int2<- lm(LifeSpan ~ Elevation*Loc_type+Species, data = res_ecto_stats)
lm_Lifespan_int4<- lm(LifeSpan ~ Elevation*Loc_type*Species, data = res_ecto_stats)
summary(lm_Lifespan) ## NO SIGNIFICANT INTERACTIONS, CHECKED MODELS BY AIC AND COMPARED FITS
Anova(lm_Lifespan, type = 2)
summary(lmm_Lifespan2)
Anova(lm_Lifespan, type = 2)
summary(glht(lm_Lifespan, linfct = mcp(Loc_type = 'Tukey')))
